<?php
namespace app\api\validate;

/**
 * 此验证器，验证多个ID是否为正整数
 */
class IDCollection extends BaseValidate
{
	protected $rule = [
		'ids' => 'require|checkIDs',
	];

	protected $message = [
		'ids.require' => 'ids必须填写',
		'ids.checkIDs' => 'ids参数必须是以逗号分隔的多个正整数',
	];

	//ids = id1,id2,...
	protected function checkIDs($value){
		$values = explode(',', $value);
		if(empty($values)){
			return false;
		}
		foreach ($values as $id) {
			// 如果不是正整数的话，返回false
			if(!$this->isPositiveInteger($id)){
				return false;
			}
		}
		return true;
	}
}